//
//  CustomerInformationManageViewController.m
//  CPICMobileServiceApp
//
//  Created by lizhiwei on 13-2-5.
//  Copyright (c) 2013年 lizhiwei. All rights reserved.
//

#import "CustomerInformationManageViewController.h"
#import "RCAlertViewUtil.h"
#import "RegexKitLite.h"
#import "NSString+SBJson.h"
#import "Config.h"
#import "UIImageView+WebCache.h"
#import "IFServiceEvaluation.h"
#import "ASIFormDataRequest.h"
#import "AppDelegate.h"
#import "ViewController.h"
#import "CustomerInfoChangePasswordViewController.h"

@interface CustomerInformationManageViewController ()

@end

@implementation CustomerInformationManageViewController
@synthesize TableCustomer;
@synthesize txtCustomerName,txtOldPassword,txtNewPassword,txtIdenPassword,txtIDNum,txtCarNum,txtContactPhone,txtEmail,txtAddress,txtFirstDate,txtCarType,txtUserAccount;
//@synthesize UpdateInfoBtn;
@synthesize UpdateInfoImage;
@synthesize progress;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {
        self.title = @"客户资料管理";
        UIBarButtonItem *rightBtnItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(addSave)];
        rightBtnItem.title=@"保存";
        self.navigationItem.rightBarButtonItem=rightBtnItem;
    }
    return self;
}

-(void)addSave
{
    if(txtOldPassword.text.length!=0)
    {
        if (txtNewPassword.text.length==0) {
            [self justShowMessage:@"新密码不能为空" title:@"注意"];
            return;
        }
        if(txtIdenPassword.text.length==0){
            [self justShowMessage:@"密码确认不能为空" title:@"注意"];
            return;
        }
        if([txtNewPassword.text isEqualToString:txtOldPassword.text])
        {
            [self justShowMessage:@"新密码不能和旧密码一样" title:@"注意"];
            return;
        }
        if ([txtNewPassword.text isEqualToString:txtIdenPassword.text]) {
            [self justShowMessage:@"密码不一致" title:@"注意"];
            return;
        }
    }
    
    if(txtIDNum.text.length!=0)
    {
        if([txtIDNum.text isMatchedByRegex:@"^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$"] ||
           [txtIDNum.text isMatchedByRegex:@"^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{4}$"]
           ||  [txtIDNum.text isMatchedByRegex:@"^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}[X]{1}$"])
        {
            
        }
        else {
            
            [self justShowMessage:@"身份证号格式不正确" title:@"注意"];
            
            return;
        }
    }


}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    NSUserDefaults *accountDefaults = [NSUserDefaults standardUserDefaults];
    NSString *bgimage= [accountDefaults objectForKey:@"UserDefaultBgKindKey"];
    
    if ([bgimage isEqualToString:@"蓝色主题风格"]) 
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88@2x.png");
        ADD_LEFT_BUTTONITEM(@"back.png");
        ADD_TITLE_NAMEITEM(@"客户资料管理");
        ADD_EXCHANGEHISTORY_BUTTONITEM(@"ChangePassword.png");
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773@2x"]];
    }
    else if([bgimage isEqualToString:@"棕色主题风格"])
    {
        ADD_BACKGROUND_BUTTONITEM(@"icon640X88_01@2x.png");
        ADD_LEFT_BUTTONITEM(@"back_01.png");
        ADD_TITLE_NAMEITEM(@"客户资料管理");
        ADD_EXCHANGEHISTORY_BUTTONITEM(@"ChangePassword.png");
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg640X773_01@2x"]];
    }
    else if([bgimage isEqualToString:@"重大节日皮肤"])
    {
        NSData *dataImg_02=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_02];
        NSLog(@"-------找到%@",dataImg_02);
        NSData *dataImg_03=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_03];
        NSData *dataImg_04=[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_DATA_04];
        
        NSURL *urlSkinImg_02=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_02]];
        NSURL *urlSkinImg_03=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_03]];
        NSURL *urlSkinImg_04=[NSURL URLWithString:[[NSUserDefaults standardUserDefaults]objectForKey:SKIN_IMG_URL_04]];
        NSLog(@"-------找到333%@",urlSkinImg_02);
        
        UIImageView * LogoImage = [[UIImageView alloc]init];
        [LogoImage setImageWithURL:urlSkinImg_03 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(LogoImage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_03];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        LogoImage.image = [UIImage imageWithData:dataImg_03];
        LogoImage.frame = CGRectMake(0, 0, LogoImage.image.size.width/2, LogoImage.image.size.height/2);
        [self.view addSubview:LogoImage];
        
        //--------------------------
        UIButton * CallOutBtn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        CallOutBtn1.frame = CGRectMake(10, 10, 109/2, 57/2);
        UIImageView * Back = [[UIImageView alloc]init];
        [Back setImageWithURL:urlSkinImg_02 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(Back.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_02];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [Back setImage:[UIImage imageWithData:dataImg_02]];
        [CallOutBtn1 setImage:Back.image forState:UIControlStateNormal];
        [CallOutBtn1 addTarget:self action:@selector(ClickCallOutBtn) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:CallOutBtn1];
        //--------------------------
        
        ADD_TITLE_NAMEITEM(@"客户资料管理");        
        
        UIImageView *bgimage = [[UIImageView alloc]initWithFrame:CGRectMake(0,44, self.view.frame.size.width, self.view.frame.size.height-44)];
        [bgimage setImageWithURL:urlSkinImg_04 success:^(UIImage *image)
         {
             NSData *imgData=UIImagePNGRepresentation(bgimage.image);
             [[NSUserDefaults standardUserDefaults] setObject:imgData forKey:SKIN_IMG_DATA_04];
         } failure:^(NSError *error)
         {
             [self justShowMessage:@"更新皮肤失败!" title:@"提示"];
         }];
        
        [bgimage setImage:[UIImage imageWithData:dataImg_04]];
        [self.view addSubview:bgimage];
        [bgimage release];
        ADD_EXCHANGEHISTORY_BUTTONITEM(@"ChangePassword.png");
    }

    
    arrTitle1=[[NSMutableArray alloc]initWithObjects:@"用户账号",@"客户姓名", nil];
    arrTitle2=[[NSMutableArray alloc]initWithObjects:@"旧密码:",@"新密码:",@"密码确认:",nil];
    arrTitle3=[[NSMutableArray alloc]initWithObjects:@"身份证号:",@"初登日期",@"手机电话:",@"邮箱地址",@"通讯地址", nil];
    //添加UITableview
    TableCustomer = [[UITableView alloc]initWithFrame:CGRectMake(8, 50, 310, self.view.frame.size.height-44-40) style:UITableViewStyleGrouped];
	TableCustomer.delegate = self;
	TableCustomer.dataSource = self;
    
    TableCustomer.opaque = NO;
    TableCustomer.backgroundView = nil;
    TableCustomer.autoresizingMask = UIViewContentModeTop;
    TableCustomer.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
    TableCustomer.backgroundColor=[UIColor clearColor];
    TableCustomer.scrollEnabled=NO;
    TableCustomer.showsHorizontalScrollIndicator=YES;
    //[TableViewUser reloadData];
	[self.view addSubview:TableCustomer];
    //[TableCustomer release];
    
    txtCustomerName=[[UITextField alloc]initWithFrame:CGRectMake(105, 5, 185, 35)];
    txtCustomerName.borderStyle=UITextBorderStyleRoundedRect;
    txtCustomerName.delegate=self;
    txtCustomerName.returnKeyType=UIReturnKeyDone;
    txtCustomerName.font = [UIFont systemFontOfSize:16.0];

    
    txtOldPassword=[[UITextField alloc]initWithFrame:CGRectMake(105, 5, 185, 35)];
    txtOldPassword.borderStyle=UITextBorderStyleRoundedRect;
    txtOldPassword.delegate=self;
    txtOldPassword.returnKeyType=UIReturnKeyDone;
    txtOldPassword.secureTextEntry=YES;
    txtOldPassword.font = [UIFont systemFontOfSize:16.0];
    
    txtNewPassword=[[UITextField alloc]initWithFrame:CGRectMake(105, 5, 185, 35)];
    txtNewPassword.borderStyle=UITextBorderStyleRoundedRect;
    txtNewPassword.delegate=self;
    txtNewPassword.returnKeyType=UIReturnKeyDone;
    txtNewPassword.secureTextEntry=YES;
    txtNewPassword.font = [UIFont systemFontOfSize:16.0];
    
    txtIdenPassword=[[UITextField alloc]initWithFrame:CGRectMake(105, 5, 185, 35)];
    txtIdenPassword.borderStyle=UITextBorderStyleRoundedRect;
    txtIdenPassword.delegate=self;
    txtIdenPassword.returnKeyType=UIReturnKeyDone;
    txtIdenPassword.secureTextEntry=YES;
    txtIdenPassword.font = [UIFont systemFontOfSize:16.0];
    
    txtIDNum=[[UITextField alloc]initWithFrame:CGRectMake(105, 5, 185, 35)];
    txtIDNum.borderStyle=UITextBorderStyleRoundedRect;
    txtIDNum.delegate=self;
    txtIDNum.returnKeyType=UIReturnKeyDone;
    txtIDNum.font = [UIFont systemFontOfSize:16.0];
    
    txtCarNum=[[UITextField alloc]initWithFrame:CGRectMake(105, 5, 185, 35)];
    txtCarNum.borderStyle=UITextBorderStyleRoundedRect;
    txtCarNum.delegate=self;
    txtCarNum.returnKeyType=UIReturnKeyDone;
    txtCarNum.font = [UIFont systemFontOfSize:16.0];
    
    txtContactPhone=[[UITextField alloc]initWithFrame:CGRectMake(105, 5, 185, 35)];
    txtContactPhone.borderStyle=UITextBorderStyleRoundedRect;
    CustomNumbleKeyboardView *customKeyboardView = [[CustomNumbleKeyboardView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 238)];
    customKeyboardView.delegate = self;
    [txtContactPhone setInputView:customKeyboardView];
    txtContactPhone.delegate=self;
    txtContactPhone.returnKeyType=UIReturnKeyDone;
    txtContactPhone.keyboardType=UIKeyboardTypeNumberPad;
    txtContactPhone.font = [UIFont systemFontOfSize:16.0];

    
    txtEmail=[[UITextField alloc]initWithFrame:CGRectMake(105, 5, 185, 35)];
    txtEmail.borderStyle=UITextBorderStyleRoundedRect;
    txtEmail.delegate=self;
    txtEmail.returnKeyType=UIReturnKeyDone;
    txtEmail.keyboardType=UIKeyboardTypeEmailAddress;
    txtEmail.font = [UIFont systemFontOfSize:16.0];

    
    txtAddress=[[UITextField alloc]initWithFrame:CGRectMake(105, 5, 185, 35)];
    txtAddress.borderStyle=UITextBorderStyleRoundedRect;
    txtAddress.delegate=self;
    txtAddress.returnKeyType=UIReturnKeyDone;
    txtAddress.font = [UIFont systemFontOfSize:16.0];
    
    txtFirstDate=[[UITextField alloc]initWithFrame:CGRectMake(105, 5, 160, 35)];
    txtFirstDate.borderStyle=UITextBorderStyleRoundedRect;
    txtFirstDate.delegate=self;
    txtFirstDate.returnKeyType=UIReturnKeyDone;
    txtFirstDate.font = [UIFont systemFontOfSize:16.0];
    txtFirstDate.enabled=NO;
    
    txtCarType=[[UITextField alloc]initWithFrame:CGRectMake(105, 5, 185, 35)];
    txtCarType.borderStyle=UITextBorderStyleRoundedRect;
    txtCarType.delegate=self;
    txtCarType.returnKeyType=UIReturnKeyDone;
    txtCarType.font = [UIFont systemFontOfSize:16.0];
    
    NSLog(@"userinfodefault%@",[[NSUserDefaults standardUserDefaults] objectForKey:DICT_USER_INFO]);
    NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_USER_INFO];
    if (dictUserInfo!=nil)
    {
        if ([dictUserInfo valueForKey:@"UserAccount"])
        {
           
        }
    }
    else
    {
        [self justShowMessage:@"用户还没登录,请登录系统" title:@"注意"];
        return;
    }
    
    txtUserAccount=[[UITextField alloc]initWithFrame:CGRectMake(105, 5, 185, 35)];
    txtUserAccount.borderStyle=UITextBorderStyleRoundedRect;
    txtUserAccount.delegate=self;
    txtUserAccount.returnKeyType=UIReturnKeyDone;
    txtUserAccount.font = [UIFont systemFontOfSize:16.0];
    txtUserAccount.text=[dictUserInfo valueForKey:@"UserAccount"];
    txtUserAccount.enabled=NO;

    
    UpdateInfoImage = [[UIImageView alloc]init];
    UpdateInfoImage.image = [UIImage imageNamed:@"Submit_suggestion.png"];
    
    UIButton *UpdateInfoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [UpdateInfoBtn setImage:UpdateInfoImage.image forState:UIControlStateNormal];
    UpdateInfoBtn.frame = CGRectMake((self.view.frame.size.width-UpdateInfoImage.image.size.width/2)/2, self.view.frame.size.height-50, UpdateInfoImage.image.size.width/2, UpdateInfoImage.image.size.height/2);
    [UpdateInfoBtn setTitle:@"更新资料" forState:UIControlStateNormal];
    [UpdateInfoBtn addTarget:self action:@selector(UpdateInfo) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:UpdateInfoBtn];
    
    UILabel * lbUpdate = [[UILabel alloc]initWithFrame:CGRectMake((self.view.frame.size.width-UpdateInfoImage.image.size.width/2)/2, self.view.frame.size.height-50-13, UpdateInfoImage.image.size.width/2, UpdateInfoImage.image.size.height/2)];
    lbUpdate.text = @"更新资料";
    lbUpdate.textAlignment = UITextAlignmentCenter;
    lbUpdate.textColor = [UIColor whiteColor];
    lbUpdate.backgroundColor = [UIColor clearColor];
    [self.view addSubview:lbUpdate];
    [lbUpdate release];
    

    txtCustomerName.text = [dictUserInfo valueForKey:@"UserName"];
    UserAccount = [dictUserInfo valueForKey:@"UserAccount"];

    
    NSDictionary * dictCustomerInfo =[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_CUSTOMER_INFO];
    if (dictCustomerInfo!=nil)
    {
        if ([dictCustomerInfo valueForKey:@"idNo"]) {
            self.txtIDNum.text=[dictCustomerInfo valueForKey:@"idNo"];
        }
        if ([dictCustomerInfo valueForKey:@"debutdate"]) {
            self.txtFirstDate.text=[dictCustomerInfo valueForKey:@"debutdate"];
        }
        if ([dictCustomerInfo valueForKey:@"phone"]) {
            self.txtContactPhone.text=[dictCustomerInfo valueForKey:@"phone"];
        }
        if ([dictCustomerInfo valueForKey:@"email"]) {
            self.txtEmail.text=[dictCustomerInfo valueForKey:@"email"];
        }
        if ([dictCustomerInfo valueForKey:@"postalAddress"]) {
            self.txtAddress.text=[dictCustomerInfo valueForKey:@"postalAddress"];
        }
    }
    else
    {
        
    }
    
    [self SETCustomerQueryRequest];
    
    [self setEvaluationRequest];
}

-(void) ClickCallOutBtn
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)ClickExchangeHistoryBtn
{
    CustomerInfoChangePasswordViewController *customerInfoChangePasswordViewCtrl=[[CustomerInfoChangePasswordViewController alloc]init];
    [self.navigationController pushViewController:customerInfoChangePasswordViewCtrl animated:YES];
    [customerInfoChangePasswordViewCtrl release];
}
-(void) UpdateInfo
{
    /*if (self.txtCustomerName.text == NULL||self.txtCustomerName==nil)
    {
        [self justShowMessage:@"先填写客户姓名" title:@"提示"];
        return;
    }*/
    
//    if (self.txtOldPassword.text == NULL||self.txtOldPassword==nil)
//    {
//        [self justShowMessage:@"先填写旧密码" title:@"提示"];
//        return;
//    }
//    
//    if (self.txtNewPassword.text == NULL||self.txtNewPassword==nil)
//    {
//        [self justShowMessage:@"先填写新密码" title:@"提示"];
//        return;
//    }
//    
//    if (self.txtIdenPassword.text == NULL||self.txtIdenPassword==nil)
//    {
//        [self justShowMessage:@"先填写密码确认" title:@"提示"];
//        return;
//    }
    
    /*if (self.txtIDNum.text == NULL||self.txtIDNum==nil)
    {
        [self justShowMessage:@"先填写身份证号" title:@"提示"];
        return;
    }
    
    if (self.txtCarNum.text == NULL||self.txtCarNum==nil)
    {
        [self justShowMessage:@"先填写车牌号" title:@"提示"];
        return;
    }
    
    if (self.txtContactPhone.text == NULL||self.txtContactPhone==nil)
    {
        [self justShowMessage:@"先填写联系电话" title:@"提示"];
        return;
    }
    
    if (self.txtEmail.text == NULL||self.txtEmail==nil)
    {
        [self justShowMessage:@"先填写邮箱地址" title:@"提示"];
        return;
    }
    
    if (self.txtAddress.text == NULL||self.txtAddress==nil)
    {
        [self justShowMessage:@"先填写通讯地址" title:@"提示"];
        return;
    }*/
    
//    if (self.txtNewPassword.text.length>0 && self.txtIdenPassword.text.length>0) 
//    {
//        if (![self.txtNewPassword.text isEqualToString:(self.txtIdenPassword.text)])
//        {
//            [self justShowMessage:@"两次密码输入不一致" title:@"提示"];
//            return;
//        }
//
//    }
    UIAlertView *alertClick=[[UIAlertView alloc]initWithTitle:@"提示" message:@"您所录入的相关个人及信息，仅为使用软件相应功能所必须，不做任何商业用途。" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    alertClick.tag=1;
    [alertClick show];
    [alertClick release];

}

#pragma UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(section==0)
    {
        return 2;
    }
    else if(section==1)
    {
        return 0;
    }
    else if(section==2)
    {
        return 5;
    }
    else
    {
        return 0;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 3;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

        static NSString *Identifier=@"Identifier";
        UITableViewCell *cell=(UITableViewCell *)[TableCustomer dequeueReusableCellWithIdentifier:Identifier];
        UILabel *lblUserAccount;

    
        if (cell==nil)
        {
            cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier]autorelease];
            cell.accessoryType = UITableViewCellAccessoryNone;
            cell.selectionStyle=UITableViewCellSelectionStyleNone;//选中后颜色没变化
            lblUserAccount=[[[UILabel alloc]initWithFrame:CGRectMake(15, 7, 85, 21)]autorelease];
            lblUserAccount.backgroundColor=[UIColor clearColor];
            lblUserAccount.font = [UIFont systemFontOfSize:16.0];
            lblUserAccount.tag=111;
            [cell addSubview:lblUserAccount];
            
        }
    NSInteger indexSection=indexPath.section;
    
    UIButton * Remindbtn = [UIButton buttonWithType:UIButtonTypeInfoDark];
    Remindbtn.frame = CGRectMake(85, 7, 18, 19);
    [Remindbtn addTarget:self action:@selector(remindclick:) forControlEvents:UIControlEventTouchUpInside];
    [cell addSubview:Remindbtn];
    UILabel *lblUserAccount111=(UILabel *)[cell viewWithTag:111];
    
    if (indexSection==0)
    {

        lblUserAccount111.text=[arrTitle1 objectAtIndex:indexPath.row];
        
        if(indexPath.row==0)
        {
            [cell addSubview:txtUserAccount];
        }
        else if(indexPath.row==1)
        {
            [cell addSubview:txtCustomerName];
            FlagStr0 = @"0";
            Remindbtn.tag = FlagStr0.intValue;
        }

    }
    else if(indexSection==1)
    {

        lblUserAccount111.text=[arrTitle2 objectAtIndex:indexPath.row];
        if(indexPath.row==0)
        {
            [cell addSubview:txtOldPassword];
            FlagStr1 = @"1";
            Remindbtn.tag = FlagStr1.intValue;
        }
        else if(indexPath.row==1)
        {
            [cell addSubview:txtNewPassword];
            FlagStr2 = @"2";
            Remindbtn.tag = FlagStr2.intValue;
        }
        else if(indexPath.row==2)
        {
            [cell addSubview:txtIdenPassword];
            FlagStr3 = @"3";
            Remindbtn.tag = FlagStr3.intValue;
        }
    }
    else if(indexSection==2)
    {

        lblUserAccount111.text=[arrTitle3 objectAtIndex:indexPath.row];
        
        if(indexPath.row==0)
        {
            [cell addSubview:txtIDNum];
            FlagStr4 = @"4";
            Remindbtn.tag = FlagStr4.intValue;
        }
//        else if(indexPath.row==1)
//        {
//            [cell addSubview:txtCarNum];
//            FlagStr5 = @"5";
//            Remindbtn.tag = FlagStr5.intValue;
//        }
        else if(indexPath.row==1)
        {
            [cell addSubview:txtFirstDate];
            FlagStr6 = @"6";
            Remindbtn.tag = FlagStr6.intValue;
            
            UIButton *btnAppointmentTime=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
            btnAppointmentTime.frame=CGRectMake(270, 3, 29, 31);
            [btnAppointmentTime addTarget:self action:@selector(setFistDateTime:) forControlEvents:UIControlEventTouchDown];
            [cell addSubview:btnAppointmentTime];
        }
//        else if(indexPath.row==3)
//        {
//            [cell addSubview:txtCarType];
//            FlagStr7 = @"7";
//            Remindbtn.tag = FlagStr7.intValue;
//        }
        else if(indexPath.row==2)
        {
            [cell addSubview:txtContactPhone];
            FlagStr8 = @"8";
            Remindbtn.tag = FlagStr8.intValue;
        }
        else if(indexPath.row==3)
        {
            [cell addSubview:txtEmail];
            FlagStr9 = @"9";
            Remindbtn.tag = FlagStr9.intValue;
        }
        else if(indexPath.row==4)
        {
            [cell addSubview:txtAddress];
            FlagStr10 = @"10";
            Remindbtn.tag = FlagStr10.intValue;
        }
    }

    return cell;
       
}
-(void)setFistDateTime:(id)sender
{
    CustomDateActionSheet *dateActionSheet=[[CustomDateActionSheet alloc]initWithDateOnlyActionHeight:284.0f WithSheetTitle:nil];
    dateActionSheet.tag=0;
    dateActionSheet.CustomDateDelegate=self;
    [dateActionSheet showInView:self.view];
    
}

-(void)ClickDate:(NSString *)Date DateActionSheetTag:(NSInteger)dateActionSheetTag
{
    if (dateActionSheetTag==0) {
        self.txtFirstDate.font=[UIFont systemFontOfSize:16.0];
         self.txtFirstDate.text=[Date substringToIndex:10];
    }
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    if(textField==txtIDNum)
    {
        [self SetAnimation:60];
    }
    else if(textField==txtCarNum)
    {
        [self SetAnimation:80];
    }
    else if(textField==txtContactPhone)
    {
        [self SetAnimation:130];
    }
    else if(textField==txtEmail)
    {
        [self SetAnimation:160];
    }
    else if(textField==txtAddress)
    {
        [self SetAnimation:200];
    }
    else if(textField==txtFirstDate)
    {
        [self SetAnimation:160];
    }
    else if(textField==txtCarType)
    {
        [self SetAnimation:200];
    }
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if(textField==txtIDNum)
    {
        [self backAnimation:60];
    }
    else if(textField==txtCarNum)
    {
        [self backAnimation:80];
    }
    else if(textField==txtContactPhone)
    {
        [self backAnimation:130];
    }
    else if(textField==txtEmail)
    {
        [self backAnimation:160];
    }
    else if(textField==txtAddress)
    {
        [self backAnimation:200];
    }
    else if(textField==txtFirstDate)
    {
        [self backAnimation:160];
    }
    else if(textField==txtCarType)
    {
        [self backAnimation:200];
    }
}
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if(textField==txtOldPassword)
    {
        if(range.location>=20)
        {
            return NO;
        }
        else
        {
            return YES;
        }
    }
    else if(textField==txtNewPassword)
    {
        if(range.location>=20)
        {
            return NO;
        }
        else
        {
            return YES;
        }
    }
    else if(textField==txtIdenPassword)
    {
        if(range.location>=20)
        {
            return NO;
        }
        else
        {
            return YES;
        }
    }
    else if(textField==txtCustomerName)
    {
        if(range.location>=20)
        {
            return NO;
        }
        else
        {
            return YES;
        }
    }
    else if(textField==txtIDNum)
    {
        if(range.location>=18)
        {
            return NO;
        }
        else
        {
            return YES;
        }
    }
    else if(textField==txtCarNum)
    {
        if(range.location>=10)
        {
            return NO;
        }
        else
        {
            return YES;
        }
    }
    else if(textField==txtContactPhone)
    {
        if(range.location>=20)
        {
            return NO;
        }
        else
        {
            return YES;
        }
    }
    else if(textField==txtEmail)
    {
        if(range.location>=50)
        {
            return NO;
        }
        else
        {
            return YES;
        }
    }
    else if(textField==txtAddress)
    {
        if(range.location>=100)
        {
            return NO;
        }
        else
        {
            return YES;
        }
    }
    return YES;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

-(void)SetAnimation:(CGFloat)Xorigin
{
    NSTimeInterval animationDuration = 0.30f;
    CGRect frame = self.view.frame;
    //frame.origin.x+=Xorigin;
    frame.origin.y-=Xorigin;
    //frame.size.height +=Xorigin;
    self.view.frame = frame;
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:animationDuration];
    self.view.frame = frame;
    [UIView commitAnimations];
}

-(void)backAnimation:(CGFloat)Xorigin
{
    NSTimeInterval animationDuration = 0.30f;
    CGRect frame = self.view.frame;
    //frame.origin.x -=Xorigin;
    frame.origin.y+=Xorigin;
    //frame.size.height -=Xorigin;
    self.view.frame = frame;
    [UIView beginAnimations:@"ResizeForKeyboard" context:nil];
    [UIView setAnimationDuration:animationDuration];
    self.view.frame = frame;
    [UIView commitAnimations];
    // [textField resignFirstResponder];
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

//数字键盘
- (void)numberKeyBoardInput:(NSInteger) number
{
    NSMutableString *textString = [[[NSMutableString alloc] initWithFormat:@"%@%d",txtContactPhone.text,number] autorelease];
    if ([textString length]>11)
    {
        [self justShowMessage:@"手机号码输入不能超过11位!" title:@""];
        return;
    }
    txtContactPhone.text = textString;
}

- (void)numberKeyBoardBackspace
{
    NSMutableString* mutableString = [[[NSMutableString alloc] initWithFormat:@"%@", txtContactPhone.text] autorelease];
    if ([mutableString length] >=1) {
        NSRange tmpRange;
        tmpRange.location = [mutableString length] - 1;
        tmpRange.length = 1;
        [mutableString deleteCharactersInRange:tmpRange];
    }
    txtContactPhone.text = mutableString;
    
}

- (void)numberKeyBoardFinish
{
    [txtContactPhone resignFirstResponder];
}

/*手机号码验证*/
-(BOOL) isValidateMobile:(NSString *)mobile
{
    //手机号以13， 15，18开头，八个 \d 数字字符
    NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    return [phoneTest evaluateWithObject:mobile];
}


-(void)setRequest//向太保移动平台发送请求报文
{
//    NSString *strRequestCode=@"RequestCode=30701";
    
    NSString *strCustomerName=[[NSString alloc]initWithFormat:@"%@",txtCustomerName.text];
    NSString *strIDNum=[[NSString alloc]initWithFormat:@"%@",txtIDNum.text];
    NSString *strCarNum=[[NSString alloc]initWithFormat:@"%@",txtCarNum.text];
    NSString *strContactPhone=[[NSString alloc]initWithFormat:@"%@",txtContactPhone.text];
    NSString *strEmail=[[NSString alloc]initWithFormat:@"%@",txtEmail.text];
    NSString *strAddress=[[NSString alloc]initWithFormat:@"%@",txtAddress.text];
    NSString *strFirstDate=[[NSString alloc]initWithFormat:@"%@",txtFirstDate.text];
    NSString *strCarType=[[NSString alloc]initWithFormat:@"%@",txtCarType.text];
    if (txtCustomerName.text.length==0) {
        strCustomerName=@"";
    }
    if (txtIDNum.text.length==0) {
        strIDNum=@"";
    }
    if (txtCarNum.text.length==0) {
        strCarNum=@"";
    }
    if (txtContactPhone.text.length==0) {
        strContactPhone=@"";
    }
    if (txtEmail.text.length==0) {
        strEmail=@"";
    }
    if (txtAddress.text.length==0) {
        strAddress=@"";
    }
    if (txtFirstDate.text.length==0) {
        strFirstDate=@"";
    }
    if (txtCarType.text.length==0) {
        strCarType=@"";
    }
    NSString *strRequestData=[NSString stringWithFormat:@"{\"userAccount\":\"%@\",\"idNo\":\"%@\",\"userName\":\"%@\",\"phone\":\"%@\",\"email\":\"%@\",\"postalAddress\":\"%@\",\"debutdate\":\"%@\"}",UserAccount,strIDNum,strCustomerName,strContactPhone,strEmail,strAddress,strFirstDate];
    //strRequestData = [strRequestData stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSLog(@"客户资料管理设置请求报文%@",strRequestData);
    
    [strCustomerName release];
    [strIDNum release];
    [strCarNum release];
    [strContactPhone release];
    [strEmail release];
    [strAddress release];
    [strFirstDate release];
    [strCarType release];
    
    NSString *urlString = [NSString stringWithFormat:Server_Url_Form];
    ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:urlString]];
    //设置需要POST的数据，这里提交两个数据，A=a&B=b
    [request setPostValue:@"30701" forKey:@"RequestCode"];
    [request setPostValue:strRequestData forKey:@"RequestData"];
    //[request startSynchronous];
    
	//设置表单提交项
    [request setDelegate:self];
    /*[request setRequestMethod:@"POST"];
    [request addRequestHeader:@"Content-Type" value:@"application/json"];
    [request setPostBody:postData];*/
    [request setDidFailSelector:@selector(ResponseFail:)];
    [request setDidFinishSelector:@selector(ResonseSuccess:)];
    [request startAsynchronous];
    
    showProgress = YES;
    if (showProgress)
    {
        progress= [[MBProgressHUD alloc]initWithView:self.view];
        [self.view addSubview:progress];
        [self.view bringSubviewToFront:progress];
        progress.labelText = @"加载中...";
        [progress show:YES];
        showProgress = NO;
    }
}

- (void)ResonseSuccess:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    
    NSString *responseString = [request responseString];
    NSLog(@"客户资料请求报文responseString %@",responseString);
    NSMutableDictionary *dictResponse=[responseString JSONValue];
    NSMutableDictionary *jsonoSubObj = [dictResponse objectForKey:@"head"];
    NSString * ss = [[NSString alloc] initWithFormat:@"%@",[jsonoSubObj objectForKey:@"success"]];
    if ([ss isEqualToString:@"1"])
    {
        AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
        delegate.viewController.lblUserName.text=txtCustomerName.text;
        
        //[self justShowMessage:@"提交成功！" title:@"提示"];
        NSDictionary *dictCustomerInfo=[[NSDictionary alloc]initWithObjectsAndKeys:txtCustomerName.text,@"userName",txtIDNum.text,@"idNo",txtContactPhone.text,@"phone",txtEmail.text,@"email",txtAddress.text,@"postalAddress",txtFirstDate.text,@"debutdate", nil];
        NSUserDefaults *myDefaults=[NSUserDefaults standardUserDefaults];
        [myDefaults setObject:dictCustomerInfo forKey:DICT_CUSTOMER_INFO];
        NSLog(@"userdefaults%@",[myDefaults objectForKey:DICT_CUSTOMER_INFO]);
        UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"更新客户资料成功！" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alertView show];
        alertView.delegate = self;
        [alertView release];
    }
    else
    {
        [self justShowMessage:[jsonoSubObj objectForKey:@"message"] title:@"提示"];
    }
}

-(void) remindclick:(id)sender
{
    UIButton *button = (UIButton *)sender;
    
    if (button.tag == FlagStr0.intValue)
    {
        [self justShowMessage:@"设置了客户姓名时，可在保单查询时，方便验证用户信息功能。" title:@"系统提示!"];
        return;
    }
    else if (button.tag == FlagStr1.intValue)
    {
        [self justShowMessage:@"请输入当前有效的密码，修改密码时，需要验证旧密码信息" title:@"系统提示!"];
    }
    else if (button.tag == FlagStr2.intValue)
    {
        [self justShowMessage:@"请设置新的登录密码" title:@"系统提示!"];
    }
    else if (button.tag == FlagStr3.intValue)
    {
        [self justShowMessage:@"请再次输入新密码，如果密码确认的内容和新密码不一致时报错。并要求重新输入密码。" title:@"系统提示!"];
    }
    else if (button.tag == FlagStr4.intValue)
    {
        [self justShowMessage:@"设置了身份证号时，可在保单查询时，方便验证用户信息功能。" title:@"系统提示!"];
    }
    else if (button.tag == FlagStr5.intValue)
    {
        [self justShowMessage:@"设置了车牌号时，可在保单查询时，方便验证用户信息功能。" title:@"系统提示!"];
    }
    else if (button.tag == FlagStr6.intValue)
    {
        [self justShowMessage:@"驾驶证初登日期。" title:@"系统提示!"];
    }
    else if (button.tag == FlagStr7.intValue)
    {
        [self justShowMessage:@"准驾车型。" title:@"系统提示!"];
    }
    else if (button.tag == FlagStr8.intValue)
    {
        [self justShowMessage:@"设置了联系电话，可在办理预约服务时，提供联系电话资料。" title:@"系统提示!"];
    }
    else if (button.tag == FlagStr9.intValue)
    {
        [self justShowMessage:@"设置了邮箱地址，可以收到您感兴趣的促销活动信息。" title:@"系统提示!"];
    }
    else if (button.tag == FlagStr10.intValue)
    {
        [self justShowMessage:@"设置了通讯地址，可以在秒杀活动结束后，方便配送。" title:@"系统提示!"];
    }
}

- (void)ResponseFail:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    
    NSLog(@"服务器连接失败!");
    [self justShowMessage:@"服务器连接失败！" title:@"提示"];
}

-(void)SETCustomerQueryRequest;//向太保移动平台发送客户资料查询请求报文
{
    NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_USER_INFO];
    if (dictUserInfo!=nil) 
    {
        if ([dictUserInfo valueForKey:@"UserAccount"]) 
        {
            //NSLog(@"%@",[dictUserInfo valueForKey:@"UserAccount"]);
        }
    }
    else
    {
        [self justShowMessage:@"用户还没登录,请登录系统" title:@"注意"];
        return;
    }
    
//    NSString *strRequestCode=@"RequestCode=62201";
    NSString *strRequestData=[NSString stringWithFormat:@"{\"userAccount\":\"%@\"}",[dictUserInfo valueForKey:@"UserAccount"]];
//    NSString *strUrl=[NSString stringWithFormat:@"%@%@%@",Server_Url,strRequestCode,strRequestData];
//    NSLog(@"++++++++++++++%@",strUrl);
//    strUrl = [strUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];//字符串编码转换
//    NSURL *myurl = [NSURL URLWithString:strUrl];//This method expects URLString to contain any necessary percent escape codes, which are ‘:’, ‘/’, ‘%’, ‘#’, ‘;’, and ‘@’. Note that ‘%’ escapes are translated via UTF-8.
//    NSLog(@"URL:%@",myurl);
    ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:Server_Url_Form]];
    //设置需要POST的数据，这里提交两个数据，A=a&B=b
    [request setPostValue:@"62201" forKey:@"RequestCode"];
    [request setPostValue:strRequestData forKey:@"RequestData"];
    
    [request setDelegate:self];
    [request setDidFailSelector:@selector(ResponseFail1:)];
    [request setDidFinishSelector:@selector(ResonseSuccess1:)];
    [request startAsynchronous];
    
    showProgress = YES;
    if (showProgress)
    {
        progress= [[MBProgressHUD alloc]initWithView:self.view];
        [self.view addSubview:progress];
        [self.view bringSubviewToFront:progress];
        progress.labelText = @"加载中...";
        [progress show:YES];
        showProgress = NO;
    }
}

- (void)ResonseSuccess1:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    NSString *responseString = [request responseString];
    NSLog(@"responseString------%@",responseString);
    NSMutableDictionary *dictResponse=[responseString JSONValue];
    NSMutableDictionary *jsonoSubObj = [dictResponse objectForKey:@"head"];
    NSString * ss = [[NSString alloc] initWithFormat:@"%@",[jsonoSubObj objectForKey:@"success"]];
    
    if ([ss isEqualToString:@"1"])
    {
        txtCustomerName.text=[dictResponse objectForKey:@"userName"];
        txtIDNum.text = [dictResponse objectForKey:@"idNo"];
        txtCarNum.text = [dictResponse objectForKey:@"license"];
        txtContactPhone.text = [dictResponse objectForKey:@"contactPhone"];
        txtEmail.text = [dictResponse objectForKey:@"email"];
        txtAddress.text = [dictResponse objectForKey:@"postalAddress"];
        txtFirstDate.text=[dictResponse objectForKey:@"debutdate"];
        txtCarType.text=[dictResponse objectForKey:@"permission"];
        
        NSDictionary *dictCustomerInfo=[[NSDictionary alloc]initWithObjectsAndKeys:txtCustomerName.text,@"userName",txtIDNum.text,@"idNo",txtContactPhone.text,@"phone",txtEmail.text,@"email",txtAddress.text,@"postalAddress",txtFirstDate.text,@"debutdate", nil];
        NSUserDefaults *myDefaults=[NSUserDefaults standardUserDefaults];
        [myDefaults setObject:dictCustomerInfo forKey:DICT_CUSTOMER_INFO];
        NSLog(@"userdefaults%@",[myDefaults objectForKey:DICT_CUSTOMER_INFO]);
    }
    else
    {
        //[self justShowMessage:@"获取客户资料信息失败！" title:@"提示"];
        return;
    }
}

- (void)ResponseFail1:(ASIHTTPRequest *)request
{
    if (!showProgress)
    {
        [progress removeFromSuperview];
        progress = nil;
    }
    NSLog(@"服务器连接失败!");
    [self justShowMessage:@"服务器连接失败！" title:@"提示"];
}

- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex
{
    switch(alert.tag)
    {
        case 0:
            if (buttonIndex == [alert cancelButtonIndex])
                //默认cancelButtonIndex = 0，每个按钮index可设
            {
//                NSString *serviceid =@"30701";
//                NSString *servicename =@"客户资料管理";
//                IFServiceEvaluation *ifserviceevaluation =[[IFServiceEvaluation alloc]initView:serviceid withserviceName:servicename];
//                [ifserviceevaluation setIfServiceEvaluationRequest];
//                [ifserviceevaluation setHidden:YES];
//                [self.view addSubview:ifserviceevaluation];
//                [ifserviceevaluation release];
                [self IFServiceEvaluation];
            }
            break;
        case 1:
            if (buttonIndex == [alert cancelButtonIndex]) {
                  [self setRequest];
            }
        default:
            break;
    }
}

-(void)setEvaluationRequest
{
    NSLog(@"==================");
    NSString *serviceid =@"30701";
    NSString *servicename =@"客户资料管理";
    IFServiceEvaluation *ifserviceevaluation =[[IFServiceEvaluation alloc]initView:serviceid withserviceName:servicename];
    [ifserviceevaluation setIfServiceEvaluationRequest];
    [ifserviceevaluation setHidden:YES];
    [self.view addSubview:ifserviceevaluation];
    [ifserviceevaluation release];
}
-(void) IFServiceEvaluation
{
    NSString *serviceid =@"30701";
    NSString *servicename =@"客户资料管理";
    NSUserDefaults *myDefaults=[NSUserDefaults standardUserDefaults];
    if ([myDefaults stringForKey:serviceid]) {
        NSString *strEvaluate=[myDefaults stringForKey:serviceid];
        if ([strEvaluate isEqualToString:@"1"]) {
            AddServiceEvaluationViewController *serviceevluation = [[AddServiceEvaluationViewController alloc]initView:serviceid withserviceName:servicename];
            [[AppDelegate app].unc pushViewController:serviceevluation animated:YES];
            [serviceevluation release];
        }
        else
        {
            [self.navigationController popToRootViewControllerAnimated:YES];
        }
    }
    else
    {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(void)dealloc
{
    [arrTitle1 release];
    [arrTitle2 release];
    [arrTitle3 release];
    [txtCustomerName release];
    [txtOldPassword release];
    [txtNewPassword release];
    [txtIdenPassword release];
    [txtIDNum release];
    [txtCarNum release];
    [txtContactPhone release];
    [txtEmail release];
    [txtAddress release];
    [TableCustomer release];
    [UpdateInfoImage release];
    [txtFirstDate release];
    [txtCarType release];
    [txtUserAccount release];
    [super dealloc];
}

@end
